home *** CD-ROM | disk | FTP | other *** search
/ FHM 100 Bombázó Ajándék CD / fhm_hu_1997.iso / fhm.exe / fhm.dxr / 00011_Cycle Graphics.ls < prev    next >
Encoding:
Text File  |  2001-03-18  |  9.6 KB  |  233 lines

  1. property spriteNum, mySprite, myFirstMember, myLastMember, myFrameTime, myTimeUnit, myPlayBackwards, myMembersList, myMemberCount, myCurrentMember, myListPosition, myLoopFlag, myMilliseconds
  2.  
  3. on getBehaviorDescription me
  4.   return "CYCLE GRAPHICS" & RETURN & RETURN & "This behavior cycles through a series of consecutive cast members" & RETURN & RETURN & "It gives you all the features of a single member filmloop, plus the possibility of precise control via Lingo.  These possibilities include speed control, starting and stopping at an arbitrary image, modifying the list of images to cycle through and more. (See 'Public Methods' below)" & RETURN & RETURN & "You simply arrange your castmembers in the order they should appear in the cycle, then use the Behavior Parameters dialog to indicate the first and last images.  You can use any type of visual member, including fields, text and buttons.  Spaces between cast members will be ignored." & RETURN & RETURN & "The regPoint of each member will appear at the loc of the current sprite.  If necessary, modify the regPoint of each member individually so that it appears in the correct position relative to the other members of the cycle." & RETURN & RETURN & "If you shift the members to different cast slots, you will need to alter the settings in the Behavior Parameters dialog: a film loop can keep track of where you drag its members to, but this behavior cannot do that." & RETURN & RETURN & "The images cannot cycle faster than the current frame tempo.  If you need to cycle faster, either increase the tempo or reduce the number of images in the list.  At speeds of more than 60 images per second, the human eye is incapable of distinguishing individual images, so higher speeds are unnecessary." & RETURN & RETURN & "PERMITTED MEMBER TYPES:" & RETURN & "Graphic members" & RETURN & RETURN & "PARAMETERS:" & RETURN & "* First/Last members: indicate which cast members to use." & RETURN & "* Rate of display of images (120 fps to 2 hours per image)" & RETURN & "* Cycle forwards or backwards" & RETURN & "* Start cycling images on beginsprite? (TRUE | FALSE)" & RETURN & "If you choose not to start cycling images on beginsprite, then you need to send a #CycleGraphics_ToggleLoop message to the sprite or the behavior to make the cycle start." & RETURN & RETURN & "PUBLIC METHODS:" & RETURN & "=> Determine which image is currently showing" & RETURN & "=> Cycle images at the frameTempo or slower" & RETURN & "=> Play the images forwards or backwards" & RETURN & "=> Start and stop at an arbitrary image" & RETURN & "=> Jump to a given image" & RETURN & "=> Determine or modify the list of images to cycle through" & RETURN & "=> Obtain the behavior reference."
  5. end
  6.  
  7. on getBehaviorTooltip me
  8.   return "Use with any graphic member, including text and buttons." & RETURN & RETURN & "This behavior cycles through a series of images at a" & RETURN & "rate independant of the frameTempo.  It gives you all" & RETURN & "the features of a single member film loop, plus precise" & RETURN & "control via Lingo.  You can stop/start the cycle, alter" & RETURN & "the speed, jump to an arbitrary member, reverse the" & RETURN & "direction of the cycle, get and set the list of members" & RETURN & "to cycle through, and determine which image is currently" & RETURN & "showing." & RETURN & RETURN & "See the 'Notes for developers' in the script itself for" & RETURN & "details."
  9. end
  10.  
  11. on beginSprite me
  12.   Initialize(me)
  13. end
  14.  
  15. on prepareFrame me
  16.   Update(me)
  17. end
  18.  
  19. on Initialize me
  20.   mySprite = sprite(me.spriteNum)
  21.   case myTimeUnit of
  22.     "images per second":
  23.       myFrameTime = 1000 / myFrameTime
  24.     "ticks per image":
  25.       myFrameTime = myFrameTime * 1000 / 60
  26.     "seconds per image":
  27.       myFrameTime = myFrameTime * 1000
  28.     "minutes per image":
  29.       myFrameTime = myFrameTime * 1000 * 60
  30.   end case
  31.   case myPlayBackwards of
  32.     #forwards:
  33.       myPlayBackwards = 0
  34.     #backwards:
  35.       myPlayBackwards = 1
  36.     otherwise:
  37.       return #invalidSymbolError
  38.   end case
  39.   myFirstMember = member(myFirstMember)
  40.   myLastMember = member(myLastMember)
  41.   minMember = min(myFirstMember.number, myLastMember.number)
  42.   maxMember = max(myFirstMember.number, myLastMember.number)
  43.   myMembersList = []
  44.   repeat with memberNumber = minMember to maxMember
  45.     theMember = member(memberNumber)
  46.     myMembersList.append(theMember)
  47.   end repeat
  48.   checkedList = StripNonGraphicMembers(me, duplicate(myMembersList))
  49.   if checkedList <> myMembersList then
  50.     ErrorAlert(me, #invalidMembers)
  51.   end if
  52.   myMemberCount = myMembersList.count()
  53.   if myPlayBackwards then
  54.     myListPosition = 1
  55.   else
  56.     myListPosition = myMemberCount
  57.   end if
  58.   myMilliseconds = the milliSeconds
  59. end
  60.  
  61. on Update me
  62.   if not myLoopFlag then
  63.     exit
  64.   end if
  65.   elapsedTime = the milliSeconds - myMilliseconds
  66.   if abs(elapsedTime < myFrameTime) then
  67.     exit
  68.   else
  69.     if elapsedTime > (myFrameTime * 2) then
  70.       myMilliseconds = the milliSeconds
  71.     end if
  72.   end if
  73.   myMilliseconds = myMilliseconds + myFrameTime
  74.   if myPlayBackwards then
  75.     myListPosition = myListPosition - 2 + myMemberCount
  76.   end if
  77.   myListPosition = (myListPosition mod myMemberCount) + 1
  78.   myCurrentMember = myMembersList[myListPosition]
  79.   mySprite.member = myCurrentMember
  80. end
  81.  
  82. on CycleGraphics_GetCurrentMember me
  83.   return myCurrentMember
  84. end
  85.  
  86. on CycleGraphics_GetMembersList me
  87.   return myMembersList
  88. end
  89.  
  90. on CycleGraphics_ToggleLoop me, trueOrFalse
  91.   if voidp(trueOrFalse) then
  92.     myLoopFlag = not myLoopFlag
  93.   else
  94.     if ilk(trueOrFalse) <> #integer then
  95.       return #invalidTypeError
  96.     else
  97.       myLoopFlag = trueOrFalse
  98.     end if
  99.   end if
  100.   if myLoopFlag then
  101.     myMilliseconds = the milliSeconds
  102.   end if
  103. end
  104.  
  105. on CycleGraphics_ToggleDirection me, playBackwards
  106.   if voidp(playBackwards) then
  107.     myPlayBackwards = not myPlayBackwards
  108.   else
  109.     case playBackwards of
  110.       #forward, #forwards, 0:
  111.         myPlayBackwards = 0
  112.       #back, #backward, #backwards, #Reverse, 1:
  113.         myPlayBackwards = 1
  114.       otherwise:
  115.         return #invalidSymbolError
  116.     end case
  117.   end if
  118.   myMilliseconds = the milliSeconds
  119. end
  120.  
  121. on CycleGraphics_ShowImage me, theImage
  122.   case ilk(theImage) of
  123.     #integer:
  124.       if (theImage < 1) or (theImage > myMemberCount) then
  125.         return #outOfRangeError
  126.       else
  127.         myListPosition = theImage
  128.         myCurrentMember = myMembersList[myListPosition]
  129.       end if
  130.     #member:
  131.       listPosition = myMembersList.getPos(theImage)
  132.       if listPosition then
  133.         myCurrentMember = theImage
  134.         myListPosition = listPosition
  135.       else
  136.         return #notInListError
  137.       end if
  138.     otherwise:
  139.       return #invalidTypeError
  140.   end case
  141.   mySprite.member = myCurrentMember
  142.   myMilliseconds = the milliSeconds
  143.   updateStage()
  144. end
  145.  
  146. on CycleGraphics_SetFrameTime me, theMilliseconds
  147.   if ilk(theMilliseconds) <> #integer then
  148.     return #invalidTypeError
  149.   else
  150.     if ilk(theMilliseconds) < 0 then
  151.       return #outOfRangeError
  152.     end if
  153.   end if
  154.   myFrameTime = theMilliseconds
  155. end
  156.  
  157. on CycleGraphics_SetMembersList me, membersList
  158.   if ilk(membersList) <> #list then
  159.     return #invalidTypeError
  160.   end if
  161.   StripNonGraphicMembers(me, membersList)
  162.   if not membersList.count() then
  163.     return #emptyListError
  164.   end if
  165.   myMembersList = membersList
  166.   myMemberCount = myMembersList.count()
  167.   if myPlayBackwards then
  168.     myListPosition = 1
  169.   else
  170.     myListPosition = myMemberCount
  171.   end if
  172. end
  173.  
  174. on CycleGraphics_GetReference me, theList
  175.   case ilk(theList) of
  176.     #list:
  177.       theList.append(me)
  178.     #propList:
  179.       theList.addProp(me.spriteNum, me)
  180.     otherwise:
  181.       return me
  182.   end case
  183.   return theList
  184. end
  185.  
  186. on StripNonGraphicMembers me, membersList
  187.   permittedTypes = [#bitmap, #button, #field, #filmLoop, #flash, #movie, #picture, #quickTimeMedia, #shape, #text, #vectorShape]
  188.   i = membersList.count()
  189.   repeat while i
  190.     theMember = membersList[i]
  191.     if ilk(theMember) <> #member then
  192.       put "'Cycle Graphics' behavior - not a member: " & theMember
  193.       membersList.deleteAt(i)
  194.     else
  195.       if not permittedTypes.getPos(theMember.type) then
  196.         put "'Cycle Graphics' behavior - invalid member: " & theMember
  197.         membersList.deleteAt(i)
  198.       end if
  199.     end if
  200.     i = i - 1
  201.   end repeat
  202.   return membersList
  203. end
  204.  
  205. on ErrorAlert me, theError, data
  206.   behaviorName = string(me)
  207.   delete word 1 of behaviorName
  208.   delete char -30001 of behaviorName
  209.   delete char -30001 of behaviorName
  210.   case data.ilk of
  211.     #void:
  212.       data = "<void>"
  213.     #symbol:
  214.       data = "#" & data
  215.   end case
  216.   case theError of
  217.     #invalidMembers:
  218.       if the runMode <> "Author" then
  219.         exit
  220.       end if
  221.       alert("BEHAVIOR ERROR: Frame " & the frame & ", Sprite " & me.spriteNum & RETURN & "Behavior " & behaviorName & RETURN & RETURN & "Certain members between " & myFirstMember & " and " & myLastMember & " are not graphical members.  Check the Message window for details.")
  222.   end case
  223. end
  224.  
  225. on getPropertyDescriptionList
  226.   if not (the currentSpriteNum) then
  227.     exit
  228.   end if
  229.   theMember = sprite(the currentSpriteNum).member
  230.   theMemberNumber = theMember.number
  231.   return [#myFirstMember: [#comment: "First member of series:", #format: #graphic, #default: theMember], #myLastMember: [#comment: "Last member of series:", #format: #graphic, #default: member(theMemberNumber + 1)], #myFrameTime: [#comment: "Display images at a maximum speed of:", #format: #integer, #range: [#min: 1, #max: 120], #default: min(the frameTempo, 120)], #myTimeUnit: [#comment: EMPTY, #format: #string, #range: ["images per second", "ticks per image", "seconds per image", "minutes per image"], #default: "images per second"], #myPlayBackwards: [#comment: "Cycle:", #format: #symbol, #range: [#forwards, #backwards], #default: #forwards], #myLoopFlag: [#comment: "Start cycling on beginSprite?", #format: #boolean, #default: 1]]
  232. end
  233.